package com.demo.java.OD401_450.OD422;

import java.util.Scanner;
import java.util.*;

/**
 * @author bug菌
 * @Source 公众号：猿圈奇妙屋
 * @des： 【虚拟游戏理财(C&D卷)】问题
 * @url： https://blog.csdn.net/weixin_43970743/article/details/146260912
 */
public class OdMain {

        public static void main(String[] args) {
            Scanner scanner = new Scanner(System.in);
            Map<String, List<String>> moveMap = new HashMap<>();

            // 读取输入数据直到结束
            while (scanner.hasNextLine()) {
                String line = scanner.nextLine().trim();
                if (line.isEmpty()) continue; // 跳过空行

                String[] parts = line.split("\\s+");
                String player = parts[0]; // 玩家ID
                String move = parts[1];   // 出拳形态 (A, B, C)

                // 将玩家加入对应出拳类别的列表中
                moveMap.putIfAbsent(move, new ArrayList<>());
                moveMap.get(move).add(player);
            }

            // 判断游戏状态
            if (moveMap.size() == 1) {
                // 所有玩家出相同的拳，平局
                System.out.println("NULL");
            } else if (moveMap.size() == 3) {
                // 三种出拳都有，平局（循环优势）
                System.out.println("NULL");
            } else {
                // 只有两种出拳，判断哪一方胜出
                List<String> winners = new ArrayList<>();
                if (moveMap.containsKey("A") && moveMap.containsKey("B")) {
                    // A > B
                    winners = moveMap.get("A");
                } else if (moveMap.containsKey("B") && moveMap.containsKey("C")) {
                    // B > C
                    winners = moveMap.get("B");
                } else if (moveMap.containsKey("C") && moveMap.containsKey("A")) {
                    // C > A
                    winners = moveMap.get("C");
                }

                // 如果有胜者，则按字典顺序排序赢家ID
                if (!winners.isEmpty()) {
                    Collections.sort(winners);
                    for (String winner : winners) {
                        System.out.println(winner);
                    }
                } else {
                    // 如果没有明确胜者，输出平局
                    System.out.println("NULL");
                }
            }
        }

}
